//
//  SecondDetailTableViewCell.m
//  CapriceMusic
//
//  Created by 蒋恩浩 on 16/1/8.
//  Copyright © 2016年 MYX. All rights reserved.
//

#import "SecondDetailTableViewCell.h"

@interface SecondDetailTableViewCell ()

@property (nonatomic, strong) JEHLabel *upDataTimeLabel;
@property (nonatomic, strong) JEHLabel *commentLabel;

@end

@implementation SecondDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        self.upDataTimeLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:12 withTextColor:[UIColor grayColor]];
        self.commentLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:14 withTextColor:[UIColor whiteColor]];
        self.commentLabel.numberOfLines = 0;
        [self addSubview:self.upDataTimeLabel];
        [self addSubview:self.commentLabel];
        for (int i = 0; i < 3; i++) {
            
            JEHLabel *label = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:12 withTextColor:[UIColor whiteColor]];
            label.tag = 100 + i;
            [self addSubview:label];
        }
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.upDataTimeLabel.frame = CGRectMake(20, 0, self.width - 40, 20);
    self.commentLabel.frame = CGRectMake(20, 40, self.width - 40, self.height - 40);
    for (int i = 0; i < 3; i++) {
        
        JEHLabel *label = (JEHLabel *)[self viewWithTag:100 + i];
        NSInteger with = (self.width - 40) / 3;
        label.frame = CGRectMake(20 + with * i, 20, with, 20);
        if (label.text.length > 0) {
            
            NSString *attributedText = [label.text substringToIndex:5];
            [label attributedText:attributedText withFont:12 withColor:[UIColor grayColor]];
        }
    }
}

- (void)setDetailModel:(DetailModel *)detailModel {
    
    if (_detailModel != detailModel) {
        
        _detailModel = detailModel;
    }
    self.upDataTimeLabel.text = [NSString stringWithFormat:@"更新时间: %@", detailModel.regdate];
    JEHLabel *playCount = (JEHLabel *)[self viewWithTag:100];
    playCount.text = [NSString stringWithFormat:@"播放次数: %d", detailModel.totalViews.intValue];
    JEHLabel *pc = (JEHLabel *)[self viewWithTag:101];
    pc.text = [NSString stringWithFormat:@"PC端: %d", detailModel.totalPcViews.intValue];
    JEHLabel *move = (JEHLabel *)[self viewWithTag:102];
    move.text = [NSString stringWithFormat:@"移动端: %d", detailModel.totalMobileViews.intValue];
    self.commentLabel.text = detailModel.descriptions;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
